package com.shortlink.mq.consumer.handle;

import com.shortlink.common.designpatten.strategy.AbstractExecuteStrategy;
import com.shortlink.mapper.LinkAccessLogsMapper;
import com.shortlink.pojos.dto.dataobject.ShortLinkStatsRecordDO;
import com.shortlink.pojos.entity.LinkAccessLogsDO;
import com.shortlink.utils.BeanCopyUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public final class LinkAccessLogsHandle extends AbstractShortLinkStatsHandle implements AbstractExecuteStrategy<AbstractShortLinkStatsHandle, Void> {

    private final LinkAccessLogsMapper linkAccessLogsMapper;

    @Override
    public void status(ShortLinkStatsRecordDO requestParam) {
        LinkAccessLogsDO linkAccessLogsDO = BeanCopyUtils.copyBean(requestParam, LinkAccessLogsDO.class);
        linkAccessLogsDO.setProvince("未知");
        linkAccessLogsMapper.insert(linkAccessLogsDO);
    }

    @Override
    public String mark() {
        return ShortLinkStatusEnum.LINK_ACCESS_LOGS.name();
    }

    public void execute(ShortLinkStatsRecordDO requestParam) {
        status(requestParam);
    }
}